package com.person.dic.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.person.commons.exception.InfrastructureException;
import com.person.commons.utils.DAO;
import com.person.dic.model.DicPara;
import com.person.dic.service.DicParaService;
import com.person.sys.model.SysLog;

/**
 * 该类用于处理系统代码
 * 
 * @author wang zitao
 * 
 */

public class DicParaServiceImpl implements DicParaService {
	private static final char SUCCESS = '1';  //修改成功
	private static final char FAIL = '0';    //修改失败
	private static final char REPEAT = '2';    //存在重复数据
	private DAO dao;

	public DAO getDao() {
		return dao;
	}

	public void setDao(DAO dao) {
		this.dao = dao;
	}
    
	
	/**
	 * 返回所有竞赛参数信息
	 * @return paras 竞赛参数信息列表
	 */
	
   public List<DicPara> seachAll(){
	   List<DicPara> paras=dao.find("from DicPara where 1=1 ");
	   if(paras.size()>0){
		   return paras;
	   }
	   else return new ArrayList();
	   
   }
   
   /**
	 * 根据No返回竞赛参数信息
	 * @return paraValue 竞赛参数信息
	 */
	
   	public Long searchByNo(String paraNo){
	   List<DicPara> paras=dao.find("select paraValue from DicPara where paraNo='"+paraNo+"'");
	   Long paraValue;
	   if(paras.size()>0){
		   Object obj=(Object)paras.get(0);
		   paraValue=Long.valueOf(obj.toString());
		   return paraValue;
	   }
	   else 
		   return new Long("0");
	   
}


/**
	 * 根据Id返回竞赛参数信息
	 * @return para 竞赛参数信息
	 */
	
public DicPara searchById(String paraId){
	   List<DicPara> paras=dao.find("from DicPara where paraId='"+paraId+"'");
	   if(paras.size()>0){
		   return paras.get(0);
	   }
	   else 
		   return new DicPara();
	   
}
   
   /**
    * 新增竞赛参数信息
    * @param para 竞赛参数信息
    */
   public char create(DicPara para){
	   try{
	   String id=(String)dao.save(para);
       return SUCCESS;
	   }catch (InfrastructureException e) {
			return FAIL;
		}
   }

   /**
    * 更新竞赛参数信息
    * @param para 竞赛参数信息对象
    */
   public char update(DicPara para){
	   try{
	   dao.update(para);
       return SUCCESS;
	   }catch (InfrastructureException e) {
			return FAIL;
		}
   }
   
   
   /**
    * 删除竞赛参数信息
    * @param para 竞赛参数对象
    */
   public char delete(String paraId){
	   try{
	   dao.delete(DicPara.class,paraId);
       return SUCCESS;
	   }catch (InfrastructureException e) {
			return FAIL;
		}
   }
}